package com.yjc.drygoods.coupon.service.impl;

import com.yjc.common.to.SkuReductionTo;
import com.yjc.drygoods.coupon.service.SkuFullReductionService;
import com.yjc.drygoods.coupon.service.SkuLadderService;
import com.yjc.drygoods.coupon.entity.SkuLadderEntity;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yjc.common.utils.PageUtils;
import com.yjc.common.utils.Query;

import com.yjc.drygoods.coupon.dao.SkuFullReductionDao;
import com.yjc.drygoods.coupon.entity.SkuFullReductionEntity;


@Service("skuFullReductionService")
public class SkuFullReductionServiceImpl extends ServiceImpl<SkuFullReductionDao, SkuFullReductionEntity> implements SkuFullReductionService {

    @Autowired
    SkuLadderService skuLadderService;

    @Autowired
    SkuFullReductionService skuFullReductionService;

    @Override
    public void saveSkuReduction(SkuReductionTo skuReductionTo) {
        //5.4）sku的优惠、满减等信息。gulisc_sms->`sms_sku_ladder`\`sms_sku_full_reduction`\`sms_member_price`
        //sms_sku_ladder
        SkuLadderEntity skuLadderEntity = new SkuLadderEntity();
        BeanUtils.copyProperties(skuReductionTo, skuLadderEntity);
        skuLadderEntity.setAddOther(skuReductionTo.getCountStatus());
        if (skuLadderEntity.getFullCount() > 0) {
            skuLadderService.saveSkuLadder(skuLadderEntity);
        }

        //sms_sku_full_reduction
        SkuFullReductionEntity skuFullReductionEntity = new SkuFullReductionEntity();
        BeanUtils.copyProperties(skuReductionTo, skuFullReductionEntity);
        skuFullReductionEntity.setAddOther(skuReductionTo.getPriceStatus());
        if (skuFullReductionEntity.getFullPrice().compareTo(new BigDecimal("0")) == 1) {
            this.saveskuFullReduction(skuFullReductionEntity);
        }

    }

    @Override
    public void saveskuFullReduction(SkuFullReductionEntity skuFullReductionEntity) {
        this.baseMapper.insert(skuFullReductionEntity);
    }

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SkuFullReductionEntity> page = this.page(
                new Query<SkuFullReductionEntity>().getPage(params),
                new QueryWrapper<SkuFullReductionEntity>()
        );

        return new PageUtils(page);
    }

}